package com.mike.server.engine.socket;

import java.io.IOException;
import java.net.UnknownHostException;

import org.apache.log4j.Logger;
import org.xsocket.connection.IServer;
import org.xsocket.connection.Server;
import org.xsocket.connection.IConnection.FlushMode;

public class EngineSocketServer {
	
	private static final Logger LOG = Logger.getLogger(EngineSocketServer.class);
	
	private static EngineSocketServer instance =  new EngineSocketServer();
	
	private EngineSocketServer() {
		//Don't allow new it outside...
	}
	
	public static EngineSocketServer getInstance() {
		return instance;
	}
	
	public static void main(String[] args) {
		EngineSocketServer.getInstance().start();
	}
	
	public void start() {
		try {
			EngineSocketConfig conf = EngineSocketConfig.getInstance();
			IServer server = new Server(conf.getHost(), conf.getPort(), EngineSocketHandler.getInstance());
			server.setFlushmode(FlushMode.ASYNC);
			server.start();
		} catch (UnknownHostException e) {
			LOG.error(e.getMessage(), e);
		} catch (IOException e) {
			LOG.error(e.getMessage(), e);
		} 
	}
}
